import * as monaco from 'monaco-editor'
import {language as sqlLanguage} from 'monaco-editor/esm/vs/basic-languages/sql/sql.js';

const sqlCompletion = monaco.languages.registerCompletionItemProvider('sql', {
	provideCompletionItems: function () {
		let suggestions = [];
		sqlLanguage.keywords.forEach(item => {
			suggestions.push({
				label: item,
				kind: monaco.languages.CompletionItemKind.Keyword,
				insertText: item
			});
		})
		sqlLanguage.operators.forEach(item => {
			suggestions.push({
				label: item,
				kind: monaco.languages.CompletionItemKind.Operator,
				insertText: item
			});
		})
		sqlLanguage.builtinFunctions.forEach(item => {
			suggestions.push({
				label: item,
				kind: monaco.languages.CompletionItemKind.Function,
				insertText: item
			});
		})
		sqlLanguage.builtinVariables.forEach(item => {
			suggestions.push({
				label: item,
				kind: monaco.languages.CompletionItemKind.Variable,
				insertText: item
			});
		})
		return {
			suggestions: suggestions
		};
	},
});

export {
	sqlCompletion
}
